﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using  PI_CS_Library.Virtual_Network_Information_Model;
using PI_CS_Tools;
using TransportLayer;
using TransportLayer.Manager;
using System.Diagnostics;

namespace  PI_CS_Library.PicsNetwork_Information_Model
{
    public class PicsMatrix : Matrix
    {
        public Dictionary<int, PicsLink> _outgoingLinkList;
        public Dictionary<int, PicsLink> _incomingLinkList;
        Dictionary<int, double> _vnWeightList;
        Dictionary<int, Virtual_Network_Information_Model.Matrix> _hostedMatrixList;
    
        public PicsMatrix(int _id, string _name, string _type, float x, float y, MatrixParameters _parameters) 
            : base(_parameters)
        {
            this._type = _type;
            this._name = _name;
            _positionX = x;
            _positionY = y;
            _outgoingLinkList = new Dictionary<int, PicsLink>();
            _incomingLinkList = new Dictionary<int, PicsLink>();
            this._id = new Identification(_id, "Physical node:");
            _hostedMatrixList = new Dictionary<int, Matrix>();
            _parameters = new MatrixParameters();
            _vnWeightList = new Dictionary<int, double>();

        }

        // Copy constructor
        public PicsMatrix(PicsMatrix _oldPicsMatrix) : base(_oldPicsMatrix)
        {
            _outgoingLinkList = new Dictionary<int, PicsLink>(_oldPicsMatrix._outgoingLinkList);
            _incomingLinkList = new Dictionary<int, PicsLink>(_oldPicsMatrix._incomingLinkList);
            _vnWeightList = new Dictionary<int, double>(_oldPicsMatrix._vnWeightList);
            _hostedMatrixList = new Dictionary<int, Matrix>(_oldPicsMatrix._hostedMatrixList);
            this._name = _oldPicsMatrix._name;
            this._type = _oldPicsMatrix._type;
            this._positionX = _oldPicsMatrix._positionX;
            this._positionY = _oldPicsMatrix._positionY;
        }

        public TransportLayer.Node GetTransportRepresentation()
        {
            TransportLayer.Node _transportNode = new TransportLayer.Node();

            _transportNode.Id = Id.Number;
            _transportNode.Name = Name;
            _transportNode.PositionX = (int)(PositionX);
            _transportNode.PositionY = (int)(PositionY);
            _transportNode.Type = Type;
            _transportNode.Delay =Parameters.Delay;

            _transportNode.PortsIn = new List<PortIn>();
            _transportNode.PortsIn.Add(new PortIn(0));
            _transportNode.PortsIn.Add(new PortIn(1));
            _transportNode.PortsIn.Add(new PortIn(2));
            _transportNode.PortsIn.Add(new PortIn(3));

            _transportNode.PortsOut = new List<PortOut>();
            _transportNode.PortsOut.Add(new PortOut(0));
            _transportNode.PortsOut.Add(new PortOut(1));
            _transportNode.PortsOut.Add(new PortOut(2));
            _transportNode.PortsOut.Add(new PortOut(3));

            return _transportNode;
        }

        public Engine.Node GetEngineRepresentation(Process _process)
        {
            Engine.Node _engineNode = new Engine.Node();

            _engineNode.Id = Id.Number;
            _engineNode.Name = Name;
            _engineNode.PositionX = (int)(PositionX);
            _engineNode.PositionY = (int)(PositionY);
            _engineNode.Type = Type;
            _engineNode.Delay = Parameters.Delay;
            _engineNode.Process = _process;

            return _engineNode;
        }

        public Dictionary<int, double> VnWeightList
        {
            get { return this._vnWeightList; }
            set { this._vnWeightList = value; }
        }

        public new Dictionary<int, PicsLink> OutgoingLinkList
        {
            get { return _outgoingLinkList; }
            set { _outgoingLinkList = value; }
        }

        public new Dictionary<int, PicsLink> IncomingLinkList
        {
            get { return _incomingLinkList; }
            set { _incomingLinkList = value; }
        }

        public Dictionary<int, Virtual_Network_Information_Model.Matrix> HostedMatrixList
        {
            get { return this._hostedMatrixList; }
            set { this._hostedMatrixList = value; }
        }

        public override string ToString()
        {
            return _id.ToString();
        }
    }

}
